<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>现代响应式网页 - 探索未来科技</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Inter', sans-serif;
            line-height: 1.6;
            color: #333;
            overflow-x: hidden;
        }

        /* 导航栏样式 */
        .navbar {
            position: fixed;
            top: 0;
            width: 100%;
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            z-index: 1000;
            padding: 1rem 0;
            transition: all 0.3s ease;
        }

        .nav-container {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 2rem;
        }

        .logo {
            font-size: 1.5rem;
            font-weight: 700;
            color: #2563eb;
        }

        .nav-links {
            display: flex;
            list-style: none;
            gap: 2rem;
        }

        .nav-links a {
            text-decoration: none;
            color: #333;
            font-weight: 500;
            transition: color 0.3s ease;
        }

        .nav-links a:hover {
            color: #2563eb;
        }

        .hamburger {
            display: none;
            flex-direction: column;
            cursor: pointer;
        }

        .hamburger span {
            width: 25px;
            height: 3px;
            background: #333;
            margin: 3px 0;
            transition: 0.3s;
        }

        /* 英雄区域 */
        .hero {
            height: 100vh;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            display: flex;
            align-items: center;
            justify-content: center;
            text-align: center;
            color: white;
            position: relative;
            overflow: hidden;
        }

        .hero::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 1000"><polygon fill="rgba(255,255,255,0.1)" points="0,1000 1000,0 1000,1000"/></svg>');
            animation: float 6s ease-in-out infinite;
        }

        @keyframes float {
            0%, 100% { transform: translateY(0px); }
            50% { transform: translateY(-20px); }
        }

        .hero-content {
            z-index: 1;
            max-width: 600px;
            padding: 0 2rem;
        }

        .hero h1 {
            font-size: 3.5rem;
            margin-bottom: 1rem;
            animation: fadeInUp 1s ease;
        }

        .hero p {
            font-size: 1.2rem;
            margin-bottom: 2rem;
            opacity: 0.9;
            animation: fadeInUp 1s ease 0.2s both;
        }

        .cta-button {
            display: inline-block;
            background: #fff;
            color: #667eea;
            padding: 1rem 2rem;
            border-radius: 50px;
            text-decoration: none;
            font-weight: 600;
            transition: all 0.3s ease;
            animation: fadeInUp 1s ease 0.4s both;
        }

        .cta-button:hover {
            transform: translateY(-3px);
            box-shadow: 0 10px 25px rgba(0,0,0,0.2);
        }

        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* 特性区域 */
        .features {
            padding: 5rem 0;
            background: #f8fafc;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 2rem;
        }

        .section-title {
            text-align: center;
            font-size: 2.5rem;
            margin-bottom: 3rem;
            color: #1e293b;
        }

        .features-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 2rem;
            margin-top: 3rem;
        }

        .feature-card {
            background: white;
            padding: 2rem;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
            transition: all 0.3s ease;
            text-align: center;
        }

        .feature-card:hover {
            transform: translateY(-10px);
            box-shadow: 0 15px 30px rgba(0,0,0,0.15);
        }

        .feature-icon {
            font-size: 3rem;
            color: #667eea;
            margin-bottom: 1rem;
        }

        .feature-card h3 {
            font-size: 1.5rem;
            margin-bottom: 1rem;
            color: #1e293b;
        }

        /* 图片画廊 */
        .gallery {
            padding: 5rem 0;
            background: white;
        }

        .gallery-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 1rem;
            margin-top: 3rem;
        }

        .gallery-item {
            position: relative;
            overflow: hidden;
            border-radius: 15px;
            cursor: pointer;
            aspect-ratio: 1;
        }

        .gallery-item img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: transform 0.3s ease;
        }

        .gallery-item:hover img {
            transform: scale(1.1);
        }

        .gallery-overlay {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0,0,0,0.7);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        .gallery-item:hover .gallery-overlay {
            opacity: 1;
        }

        /* 交互区域 */
        .interactive {
            padding: 5rem 0;
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
        }

        .interactive-content {
            text-align: center;
        }

        .counter-section {
            margin: 2rem 0;
        }

        .counter {
            font-size: 3rem;
            font-weight: 700;
            margin: 1rem 0;
        }

        .counter-buttons {
            display: flex;
            gap: 1rem;
            justify-content: center;
            margin: 2rem 0;
        }

        .btn {
            padding: 0.8rem 1.5rem;
            border: none;
            border-radius: 25px;
            cursor: pointer;
            font-weight: 600;
            transition: all 0.3s ease;
        }

        .btn-primary {
            background: white;
            color: #f5576c;
        }

        .btn-secondary {
            background: transparent;
            color: white;
            border: 2px solid white;
        }

        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }

        /* 表单区域 */
        .contact {
            padding: 5rem 0;
            background: #f8fafc;
        }

        .contact-form {
            max-width: 600px;
            margin: 0 auto;
            background: white;
            padding: 2rem;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
        }

        .form-group {
            margin-bottom: 1.5rem;
        }

        .form-group label {
            display: block;
            margin-bottom: 0.5rem;
            font-weight: 600;
            color: #1e293b;
        }

        .form-group input,
        .form-group textarea {
            width: 100%;
            padding: 0.8rem;
            border: 1px solid #e2e8f0;
            border-radius: 8px;
            font-family: inherit;
        }

        .form-group textarea {
            resize: vertical;
            min-height: 100px;
        }

        /* 模态框 */
        .modal {
            display: none;
            position: fixed;
            z-index: 2000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.8);
        }

        .modal-content {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: white;
            padding: 2rem;
            border-radius: 15px;
            max-width: 500px;
            width: 90%;
            text-align: center;
        }

        .close {
            position: absolute;
            top: 10px;
            right: 15px;
            font-size: 2rem;
            cursor: pointer;
            color: #666;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .nav-links {
                display: none;
            }

            .hamburger {
                display: flex;
            }

            .hero h1 {
                font-size: 2.5rem;
            }

            .features-grid {
                grid-template-columns: 1fr;
            }

            .counter-buttons {
                flex-direction: column;
                align-items: center;
            }
        }

        /* 动画效果 */
        .fade-in {
            opacity: 0;
            transform: translateY(30px);
            transition: all 0.6s ease;
        }

        .fade-in.visible {
            opacity: 1;
            transform: translateY(0);
        }

        /* 消息管理区域样式 */
        .messages-section {
            padding: 5rem 0;
            background: #1e293b;
            color: white;
        }

        .messages-controls {
            text-align: center;
            margin-bottom: 2rem;
        }

        .messages-controls .btn {
            margin: 0 0.5rem;
        }

        .messages-container {
            max-width: 1000px;
            margin: 0 auto;
        }

        .messages-stats {
            display: flex;
            justify-content: center;
            gap: 2rem;
            margin-bottom: 2rem;
            font-size: 1.1rem;
        }

        .messages-stats span {
            color: #60a5fa;
            font-weight: bold;
        }

        .messages-list {
            display: grid;
            gap: 1rem;
            max-height: 600px;
            overflow-y: auto;
            padding: 1rem;
        }

        .message-card {
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 10px;
            padding: 1.5rem;
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }

        .message-card:hover {
            background: rgba(255, 255, 255, 0.15);
            transform: translateY(-2px);
        }

        .message-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1rem;
            flex-wrap: wrap;
        }

        .message-name {
            font-size: 1.2rem;
            font-weight: 600;
            color: #60a5fa;
        }

        .message-email {
            color: #94a3b8;
            font-size: 0.9rem;
        }

        .message-date {
            color: #64748b;
            font-size: 0.8rem;
        }

        .message-subject {
            font-size: 1.1rem;
            font-weight: 500;
            margin-bottom: 0.5rem;
            color: #e2e8f0;
        }

        .message-content {
            color: #cbd5e1;
            line-height: 1.6;
            white-space: pre-wrap;
        }

        .message-actions {
            display: flex;
            gap: 0.5rem;
            margin-top: 1rem;
        }

        .message-actions button {
            padding: 0.3rem 0.8rem;
            font-size: 0.8rem;
            border: none;
            border-radius: 15px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .btn-delete {
            background: #ef4444;
            color: white;
        }

        .btn-delete:hover {
            background: #dc2626;
        }

        /* 滚动条样式 */
        ::-webkit-scrollbar {
            width: 8px;
        }

        ::-webkit-scrollbar-track {
            background: #f1f1f1;
        }

        ::-webkit-scrollbar-thumb {
            background: #667eea;
            border-radius: 4px;
        }

        ::-webkit-scrollbar-thumb:hover {
            background: #5a6fd8;
        }
    </style>
</head>
<body>
<!-- 导航栏 -->
<nav class="navbar">
    <div class="nav-container">
        <div class="logo">TechFuture</div>
        <ul class="nav-links">
            <li><a href="#home">首页</a></li>
            <li><a href="#features">特性</a></li>
            <li><a href="#gallery">画廊</a></li>
            <li><a href="#interactive">互动</a></li>
            <li><a href="#contact">联系</a></li>
            <li><a href="#messages">消息管理</a></li>
        </ul>
        <div class="hamburger" onclick="toggleMenu()">
            <span></span>
            <span></span>
            <span></span>
        </div>
    </div>
</nav>

<!-- 英雄区域 -->
<section id="home" class="hero">
    <div class="hero-content">
        <h1>探索未来科技的无限可能</h1>
        <p>欢迎来到数字时代的创新前沿，在这里，每一个创意都能成为改变世界的力量</p>
        <a href="#features" class="cta-button">开始探索</a>
    </div>
</section>

<!-- 特性区域 -->
<section id="features" class="features">
    <div class="container">
        <h2 class="section-title fade-in">核心特性</h2>
        <div class="features-grid">
            <div class="feature-card fade-in">
                <div class="feature-icon">
                    <i class="fas fa-rocket"></i>
                </div>
                <h3>极速性能</h3>
                <p>采用最新技术栈，确保网页加载速度极快，用户体验流畅无比</p>
            </div>
            <div class="feature-card fade-in">
                <div class="feature-icon">
                    <i class="fas fa-mobile-alt"></i>
                </div>
                <h3>完全响应式</h3>
                <p>完美适配各种设备，从手机到平板再到桌面，都能获得最佳浏览体验</p>
            </div>
            <div class="feature-card fade-in">
                <div class="feature-icon">
                    <i class="fas fa-palette"></i>
                </div>
                <h3>精美设计</h3>
                <p>现代化的UI设计，优雅的动画效果，让每一次交互都成为视觉享受</p>
            </div>
            <div class="feature-card fade-in">
                <div class="feature-icon">
                    <i class="fas fa-shield-alt"></i>
                </div>
                <h3>安全可靠</h3>
                <p>采用业界标准的安全措施，保护用户数据，确保网站稳定运行</p>
            </div>
            <div class="feature-card fade-in">
                <div class="feature-icon">
                    <i class="fas fa-users"></i>
                </div>
                <h3>社区支持</h3>
                <p>活跃的用户社区，专业的技术支持，随时解答您的疑问</p>
            </div>
            <div class="feature-card fade-in">
                <div class="feature-icon">
                    <i class="fas fa-cog"></i>
                </div>
                <h3>易于定制</h3>
                <p>灵活的架构设计，丰富的配置选项，轻松打造专属的网站风格</p>
            </div>
        </div>
    </div>
</section>

<!-- 图片画廊 -->
<section id="gallery" class="gallery">
    <div class="container">
        <h2 class="section-title fade-in">精美画廊</h2>
        <div class="gallery-grid">
            <div class="gallery-item fade-in" onclick="openModal('https://via.placeholder.com/500x500/6366f1/ffffff?text=未来城市')">
                <img src="https://via.placeholder.com/500x500/6366f1/ffffff?text=未来城市" alt="未来城市">
                <div class="gallery-overlay">
                    <h3>未来城市</h3>
                </div>
            </div>
            <div class="gallery-item fade-in" onclick="openModal('https://via.placeholder.com/500x500/3b82f6/ffffff?text=科技创新')">
                <img src="https://via.placeholder.com/500x500/3b82f6/ffffff?text=科技创新" alt="科技创新">
                <div class="gallery-overlay">
                    <h3>科技创新</h3>
                </div>
            </div>
            <div class="gallery-item fade-in" onclick="openModal('https://via.placeholder.com/500x500/10b981/ffffff?text=数字世界')">
                <img src="https://via.placeholder.com/500x500/10b981/ffffff?text=数字世界" alt="数字世界">
                <div class="gallery-overlay">
                    <h3>数字世界</h3>
                </div>
            </div>
            <div class="gallery-item fade-in" onclick="openModal('https://via.placeholder.com/500x500/8b5cf6/ffffff?text=人工智能')">
                <img src="https://via.placeholder.com/500x500/8b5cf6/ffffff?text=人工智能" alt="人工智能">
                <div class="gallery-overlay">
                    <h3>人工智能</h3>
                </div>
            </div>
            <div class="gallery-item fade-in" onclick="openModal('https://via.placeholder.com/500x500/f59e0b/ffffff?text=虚拟现实')">
                <img src="https://via.placeholder.com/500x500/f59e0b/ffffff?text=虚拟现实" alt="虚拟现实">
                <div class="gallery-overlay">
                    <h3>虚拟现实</h3>
                </div>
            </div>
            <div class="gallery-item fade-in" onclick="openModal('https://via.placeholder.com/500x500/ef4444/ffffff?text=团队协作')">
                <img src="https://via.placeholder.com/500x500/ef4444/ffffff?text=团队协作" alt="团队协作">
                <div class="gallery-overlay">
                    <h3>团队协作</h3>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- 交互区域 -->
<section id="interactive" class="interactive">
    <div class="container">
        <div class="interactive-content fade-in">
            <h2>互动体验</h2>
            <p>点击下方按钮，体验实时交互功能</p>

            <div class="counter-section">
                <h3>计数器</h3>
                <div class="counter" id="counter">0</div>
                <div class="counter-buttons">
                    <button class="btn btn-primary" onclick="increment()">增加</button>
                    <button class="btn btn-secondary" onclick="decrement()">减少</button>
                    <button class="btn btn-secondary" onclick="reset()">重置</button>
                </div>
            </div>

            <div class="counter-section">
                <h3>颜色变换</h3>
                <div class="counter-buttons">
                    <button class="btn btn-primary" onclick="changeColor('blue')">蓝色主题</button>
                    <button class="btn btn-secondary" onclick="changeColor('green')">绿色主题</button>
                    <button class="btn btn-secondary" onclick="changeColor('purple')">紫色主题</button>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- 联系表单 -->
<section id="contact" class="contact">
    <div class="container">
        <h2 class="section-title fade-in">联系我们</h2>
        <form class="contact-form fade-in" onsubmit="handleSubmit(event)">
            <div class="form-group">
                <label for="name">姓名</label>
                <input type="text" id="name" name="name" required>
            </div>
            <div class="form-group">
                <label for="email">邮箱</label>
                <input type="email" id="email" name="email" required>
            </div>
            <div class="form-group">
                <label for="subject">主题</label>
                <input type="text" id="subject" name="subject" required>
            </div>
            <div class="form-group">
                <label for="message">留言</label>
                <textarea id="message" name="message" required></textarea>
            </div>
            <button type="submit" class="btn btn-primary">发送消息</button>
        </form>
    </div>
</section>

<!-- 消息管理区域 -->
<section id="messages" class="messages-section">
    <div class="container">
        <h2 class="section-title fade-in">消息管理</h2>
        <div class="messages-controls fade-in">
            <button class="btn btn-primary" onclick="toggleMessages()">显示/隐藏消息</button>
            <button class="btn btn-secondary" onclick="generateDemoData()">生成演示数据</button>
            <button class="btn btn-secondary" onclick="clearAllMessages()">清空所有消息</button>
            <button class="btn btn-secondary" onclick="exportMessages()">导出数据</button>
            <input type="text" id="search-input" placeholder="搜索消息..."
                   style="padding: 0.5rem; border-radius: 20px; border: none; margin-left: 1rem;"
                   oninput="searchMessages(this.value)">
        </div>
        <div id="messages-container" class="messages-container fade-in" style="display: none;">
            <div class="messages-stats">
                <p>总消息数: <span id="total-messages">0</span></p>
                <p>今日消息: <span id="today-messages">0</span></p>
            </div>
            <div id="messages-list" class="messages-list"></div>
        </div>
    </div>
</section>

<!-- 模态框 -->
<div id="modal" class="modal" onclick="closeModal(event)">
    <div class="modal-content">
        <span class="close" onclick="closeModal(event)">&times;</span>
        <img id="modal-img" src="" alt="" style="width: 100%; border-radius: 10px;">
    </div>
</div>

<script>
    // 全局变量
    let count = 0;
    let currentTheme = 'purple';

    // 导航栏滚动效果
    window.addEventListener('scroll', function() {
        const navbar = document.querySelector('.navbar');
        if (window.scrollY > 100) {
            navbar.style.background = 'rgba(255, 255, 255, 0.98)';
            navbar.style.boxShadow = '0 2px 10px rgba(0,0,0,0.1)';
        } else {
            navbar.style.background = 'rgba(255, 255, 255, 0.95)';
            navbar.style.boxShadow = 'none';
        }
    });

    // 平滑滚动
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function (e) {
            e.preventDefault();
            const target = document.querySelector(this.getAttribute('href'));
            if (target) {
                target.scrollIntoView({
                    behavior: 'smooth',
                    block: 'start'
                });
            }
        });
    });

    // 移动端菜单切换
    function toggleMenu() {
        const navLinks = document.querySelector('.nav-links');
        navLinks.style.display = navLinks.style.display === 'flex' ? 'none' : 'flex';
    }

    // 计数器功能
    function increment() {
        count++;
        updateCounter();
        showNotification('计数增加！');
    }

    function decrement() {
        count--;
        updateCounter();
        showNotification('计数减少！');
    }

    function reset() {
        count = 0;
        updateCounter();
        showNotification('计数已重置！');
    }

    function updateCounter() {
        const counterElement = document.getElementById('counter');
        counterElement.textContent = count;
        counterElement.style.transform = 'scale(1.2)';
        setTimeout(() => {
            counterElement.style.transform = 'scale(1)';
        }, 200);
    }

    // 颜色主题切换
    function changeColor(theme) {
        const root = document.documentElement;
        const themes = {
            blue: {
                primary: '#3b82f6',
                secondary: '#1d4ed8',
                gradient: 'linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%)'
            },
            green: {
                primary: '#10b981',
                secondary: '#047857',
                gradient: 'linear-gradient(135deg, #10b981 0%, #047857 100%)'
            },
            purple: {
                primary: '#8b5cf6',
                secondary: '#7c3aed',
                gradient: 'linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%)'
            }
        };

        const selectedTheme = themes[theme];
        document.querySelector('.interactive').style.background = selectedTheme.gradient;
        currentTheme = theme;
        showNotification(`已切换到${theme === 'blue' ? '蓝色' : theme === 'green' ? '绿色' : '紫色'}主题！`);
    }

    // 模态框功能
    function openModal(imageSrc) {
        const modal = document.getElementById('modal');
        const modalImg = document.getElementById('modal-img');
        modal.style.display = 'block';
        modalImg.src = imageSrc;
    }

    function closeModal(event) {
        const modal = document.getElementById('modal');
        if (event.target === modal || event.target.classList.contains('close')) {
            modal.style.display = 'none';
        }
    }

    // 表单提交处理
    function handleSubmit(event) {
        event.preventDefault();
        const formData = new FormData(event.target);
        const data = Object.fromEntries(formData);

        // 模拟表单提交
        showNotification('消息发送成功！我们会尽快回复您。');
        event.target.reset();
    }

    // 通知功能
    function showNotification(message) {
        const notification = document.createElement('div');
        notification.style.cssText = `
                position: fixed;
                top: 20px;
                right: 20px;
                background: #10b981;
                color: white;
                padding: 1rem 2rem;
                border-radius: 8px;
                box-shadow: 0 4px 12px rgba(0,0,0,0.15);
                z-index: 3000;
                animation: slideIn 0.3s ease;
            `;
        notification.textContent = message;
        document.body.appendChild(notification);

        setTimeout(() => {
            notification.style.animation = 'slideOut 0.3s ease';
            setTimeout(() => notification.remove(), 300);
        }, 3000);
    }

    // 滚动动画
    function handleScrollAnimation() {
        const elements = document.querySelectorAll('.fade-in');
        elements.forEach(element => {
            const elementTop = element.getBoundingClientRect().top;
            const elementVisible = 150;

            if (elementTop < window.innerHeight - elementVisible) {
                element.classList.add('visible');
            }
        });
    }

    // 打字机效果
    function typeWriter(element, text, speed = 100) {
        let i = 0;
        element.innerHTML = '';
        function type() {
            if (i < text.length) {
                element.innerHTML += text.charAt(i);
                i++;
                setTimeout(type, speed);
            }
        }
        type();
    }

    // 数据库管理功能
    class MessageDatabase {
        constructor() {
            this.storageKey = 'website_messages';
            this.messages = this.loadMessages();
        }

        loadMessages() {
            const data = localStorage.getItem(this.storageKey);
            return data ? JSON.parse(data) : [];
        }

        saveMessages() {
            localStorage.setItem(this.storageKey, JSON.stringify(this.messages));
        }

        addMessage(messageData) {
            const message = {
                id: Date.now() + Math.random(),
                name: messageData.name,
                email: messageData.email,
                subject: messageData.subject,
                message: messageData.message,
                timestamp: new Date().toISOString(),
                date: new Date().toLocaleString('zh-CN')
            };
            this.messages.unshift(message); // 添加到开头
            this.saveMessages();
            return message;
        }

        getMessages() {
            return this.messages;
        }

        deleteMessage(id) {
            this.messages = this.messages.filter(msg => msg.id !== id);
            this.saveMessages();
        }

        clearAll() {
            this.messages = [];
            this.saveMessages();
        }

        getStats() {
            const today = new Date().toDateString();
            const todayMessages = this.messages.filter(msg =>
                new Date(msg.timestamp).toDateString() === today
            );
            return {
                total: this.messages.length,
                today: todayMessages.length
            };
        }
    }

    // 创建数据库实例
    const messageDB = new MessageDatabase();

    // 修改表单提交处理
    function handleSubmit(event) {
        event.preventDefault();
        const formData = new FormData(event.target);
        const data = Object.fromEntries(formData);

        // 保存到数据库
        const savedMessage = messageDB.addMessage(data);

        // 显示成功通知
        showNotification('消息发送成功！已保存到数据库。');

        // 更新消息显示
        displayMessages();

        // 重置表单
        event.target.reset();
    }

    // 显示消息列表
    function displayMessages() {
        const messagesList = document.getElementById('messages-list');
        const messages = messageDB.getMessages();
        const stats = messageDB.getStats();

        // 更新统计信息
        document.getElementById('total-messages').textContent = stats.total;
        document.getElementById('today-messages').textContent = stats.today;

        if (messages.length === 0) {
            messagesList.innerHTML = '<p style="text-align: center; color: #64748b;">暂无消息</p>';
            return;
        }

        messagesList.innerHTML = messages.map(msg => `
                <div class="message-card" data-id="${msg.id}">
                    <div class="message-header">
                        <div>
                            <div class="message-name">${escapeHtml(msg.name)}</div>
                            <div class="message-email">${escapeHtml(msg.email)}</div>
                        </div>
                        <div class="message-date">${msg.date}</div>
                    </div>
                    <div class="message-subject">${escapeHtml(msg.subject)}</div>
                    <div class="message-content">${escapeHtml(msg.message)}</div>
                    <div class="message-actions">
                        <button class="btn-delete" onclick="deleteMessage(${msg.id})">删除</button>
                    </div>
                </div>
            `).join('');
    }

    // HTML转义函数
    function escapeHtml(text) {
        const div = document.createElement('div');
        div.textContent = text;
        return div.innerHTML;
    }

    // 切换消息显示
    function toggleMessages() {
        const container = document.getElementById('messages-container');
        const isVisible = container.style.display !== 'none';

        if (!isVisible) {
            displayMessages();
            container.style.display = 'block';
            // 滚动到消息区域
            document.getElementById('messages').scrollIntoView({
                behavior: 'smooth',
                block: 'start'
            });
        } else {
            container.style.display = 'none';
        }
    }

    // 清空所有消息
    function clearAllMessages() {
        if (confirm('确定要清空所有消息吗？此操作不可恢复！')) {
            messageDB.clearAll();
            displayMessages();
            showNotification('所有消息已清空！');
        }
    }

    // 导出消息数据
    function exportMessages() {
        const messages = messageDB.getMessages();
        const dataStr = JSON.stringify(messages, null, 2);
        const dataBlob = new Blob([dataStr], { type: 'application/json' });

        const link = document.createElement('a');
        link.href = URL.createObjectURL(dataBlob);
        link.download = `messages_${new Date().toISOString().split('T')[0]}.json`;
        link.click();

        showNotification('数据已导出！');
    }

    // 删除单条消息
    function deleteMessage(id) {
        if (confirm('确定要删除这条消息吗？')) {
            messageDB.deleteMessage(id);
            displayMessages();
            showNotification('消息已删除！');
        }
    }

    // 搜索功能
    function searchMessages(query) {
        const messages = messageDB.getMessages();
        if (!query.trim()) {
            displayMessages();
            return;
        }

        const filtered = messages.filter(msg =>
            msg.name.toLowerCase().includes(query.toLowerCase()) ||
            msg.email.toLowerCase().includes(query.toLowerCase()) ||
            msg.subject.toLowerCase().includes(query.toLowerCase()) ||
            msg.message.toLowerCase().includes(query.toLowerCase())
        );

        const messagesList = document.getElementById('messages-list');
        if (filtered.length === 0) {
            messagesList.innerHTML = '<p style="text-align: center; color: #64748b;">没有找到匹配的消息</p>';
            return;
        }

        messagesList.innerHTML = filtered.map(msg => `
                <div class="message-card" data-id="${msg.id}">
                    <div class="message-header">
                        <div>
                            <div class="message-name">${escapeHtml(msg.name)}</div>
                            <div class="message-email">${escapeHtml(msg.email)}</div>
                        </div>
                        <div class="message-date">${msg.date}</div>
                    </div>
                    <div class="message-subject">${escapeHtml(msg.subject)}</div>
                    <div class="message-content">${escapeHtml(msg.message)}</div>
                    <div class="message-actions">
                        <button class="btn-delete" onclick="deleteMessage(${msg.id})">删除</button>
                    </div>
                </div>
            `).join('');
    }

    // 生成演示数据
    function generateDemoData() {
        const demoMessages = [
            {
                name: "张三",
                email: "zhangsan@example.com",
                subject: "网站设计咨询",
                message: "您好！我对贵公司的网站设计服务很感兴趣，希望能了解更多详情。"
            },
            {
                name: "李四",
                email: "lisi@example.com",
                subject: "技术支持",
                message: "我在使用网站时遇到了一些技术问题，希望能得到帮助。具体问题是页面加载速度较慢。"
            },
            {
                name: "王五",
                email: "wangwu@example.com",
                subject: "合作提案",
                message: "我们是一家新兴的科技公司，希望与贵公司建立合作关系，共同开发创新产品。"
            }
        ];

        demoMessages.forEach(msg => {
            messageDB.addMessage(msg);
        });

        displayMessages();
        showNotification('演示数据已生成！');
    }

    // 页面加载完成后的初始化
    document.addEventListener('DOMContentLoaded', function() {
        handleScrollAnimation();

        // 为英雄区域添加打字机效果
        const heroTitle = document.querySelector('.hero h1');
        const originalText = heroTitle.textContent;
        typeWriter(heroTitle, originalText, 80);

        // 初始化消息显示
        displayMessages();
    });

    // 监听滚动事件
    window.addEventListener('scroll', handleScrollAnimation);

    // 键盘快捷键
    document.addEventListener('keydown', function(e) {
        if (e.ctrlKey || e.metaKey) {
            switch(e.key) {
                case '1':
                    e.preventDefault();
                    document.querySelector('#home').scrollIntoView({ behavior: 'smooth' });
                    break;
                case '2':
                    e.preventDefault();
                    document.querySelector('#features').scrollIntoView({ behavior: 'smooth' });
                    break;
                case '3':
                    e.preventDefault();
                    document.querySelector('#gallery').scrollIntoView({ behavior: 'smooth' });
                    break;
                case '4':
                    e.preventDefault();
                    document.querySelector('#interactive').scrollIntoView({ behavior: 'smooth' });
                    break;
                case '5':
                    e.preventDefault();
                    document.querySelector('#contact').scrollIntoView({ behavior: 'smooth' });
                    break;
            }
        }
    });

    // 鼠标跟随效果
    document.addEventListener('mousemove', function(e) {
        const cursor = document.querySelector('.cursor');
        if (!cursor) {
            const newCursor = document.createElement('div');
            newCursor.className = 'cursor';
            newCursor.style.cssText = `
                    position: fixed;
                    width: 20px;
                    height: 20px;
                    background: rgba(102, 126, 234, 0.5);
                    border-radius: 50%;
                    pointer-events: none;
                    z-index: 9999;
                    transition: transform 0.1s ease;
                `;
            document.body.appendChild(newCursor);
        }

        const cursorElement = document.querySelector('.cursor');
        cursorElement.style.left = e.clientX - 10 + 'px';
        cursorElement.style.top = e.clientY - 10 + 'px';
    });

    // 添加CSS动画关键帧
    const style = document.createElement('style');
    style.textContent = `
            @keyframes slideIn {
                from {
                    transform: translateX(100%);
                    opacity: 0;
                }
                to {
                    transform: translateX(0);
                    opacity: 1;
                }
            }

            @keyframes slideOut {
                from {
                    transform: translateX(0);
                    opacity: 1;
                }
                to {
                    transform: translateX(100%);
                    opacity: 0;
                }
            }
        `;
    document.head.appendChild(style);
</script>
</body>
</html>